home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / nkcc-gc.s < prev    next >
Encoding:
Text File  |  1998-03-29  |  25.0 KB  |  785 lines

  1. |***************************************************************************
  2. |
  3. |    Reduzierte NKCC für die CF-Lib
  4. |    Version für GNU-C
  5. |
  6. |***************************************************************************
  7.  
  8. |***************************************************************************
  9. |                          ASSEMBLER CONTROL SECTION                        *
  10. |***************************************************************************
  11.  
  12. VERSION         =    0x0294            | NKCC's version #
  13.  
  14. NKFf_FUNC        =    0x8000
  15. NKFf_RESVD        =    0x4000
  16. NKFf_NUM        =    0x2000
  17. NKFf_CAPS        =    0x1000
  18. NKFf_ALT        =    0x0800
  19. NKFf_CTRL        =    0x0400
  20. NKFf_SHIFT        =    0x0300            | both shift keys
  21.  
  22. NKFb_FUNC        =    15                | function
  23. NKFb_RESVD        =    14                | reserved, ignore it!
  24. NKFb_NUM        =    13                | numeric pad
  25. NKFb_CAPS        =    12                | CapsLock
  26. NKFb_ALT        =    11                | Alternate
  27. NKFb_CTRL        =    10                | Control
  28. NKFb_LSH        =    9                | left Shift key
  29. NKFb_RSH        =    8                | right Shift key
  30.  
  31. NK_UP            =    0x01            | cursor up
  32. NK_DOWN         =    0x02            | cursor down
  33. NK_RIGHT        =    0x03            | cursor right
  34. NK_LEFT         =    0x04            | cursor left
  35. NK_M_PGUP        =    0x05            | Mac: page up
  36. NK_M_PGDOWN     =    0x06            | Mac: page down
  37. NK_M_END        =    0x07            | Mac: end
  38. NK_INS            =    0x0b            | Insert
  39. NK_CLRHOME        =    0x0c            | Clr/Home
  40. NK_HELP         =    0x0e            | Help
  41. NK_UNDO         =    0x0f            | Undo
  42. NK_M_F11        =    0x1a            | Mac: function key #11
  43. NK_M_F12        =    0x1c            | Mac: function key #12
  44. NK_M_F14        =    0x1d            | Mac: function key #14
  45. NK_ENTER        =    0x0a            | Enter
  46. NK_DEL            =    0x1f            | Delete
  47.  
  48. |***************************************************************************
  49. |                                    EXPORT                                     *
  50. |***************************************************************************
  51.  
  52.                 .globl    _nkc_init            | init NKCC
  53.                 .globl    _nkc_tos2n            | TOS key code converter
  54.                 .globl    _nkc_n2tos            | NKC to TOS key code converter
  55.                 .globl    _nkc_toupper        | convert character to upper case
  56.                 .globl    _nkc_tolower        | convert character to lower case
  57.  
  58. |***************************************************************************
  59. |                             LOCAL TEXT SECTION                              *
  60. |***************************************************************************
  61.  
  62. |***************************************************************************
  63. |
  64. |  nk_findscan: find scan code
  65. |
  66. |***************************************************************************
  67.  
  68. nk_findscan:    btst     #NKFb_NUM,d0        | on numeric keypad?
  69.                 beqs     search                | no ->
  70.  
  71.                 movew    #0x4a,d1            | yes: try all numeric keypad
  72.                 cmpb     a0@(d1:w),d0        |    scan codes first
  73.                 beqs     found1                | it matches ->
  74.  
  75.                 movew    #0x4e,d1
  76.                 cmpb     a0@(d1:w),d0
  77.                 beqs     found1
  78.  
  79.                 movew    #0x63,d1            | block starts at 0x63
  80.  
  81. numsearch:        cmpb     a0@(d1:w),d0        | match?
  82.                 beqs     found1                | yes ->
  83.  
  84.                 addqw    #1,d1                | next scan code
  85.                 cmpw     #0x73,d1            | block end at 0x72
  86.                 bcss     numsearch            | continue search ->
  87.  
  88. search:         movew    #1,d1                | start with first valid scan code
  89.  
  90. mainsearch:        cmpb     a0@(d1:w),d0        | match?
  91.                 beqs     found1                | yes ->
  92.  
  93.                 addqb    #1,d1                | next scan code
  94.                 cmpb     #0x78,d1            | 0x78 = last valid scan code
  95.                 bcss     mainsearch            | continue search ->
  96.  
  97.                 moveql    #0,d1                | not found
  98.                 rts
  99.  
  100. found1:         tstw     d1                    | found set CCR
  101.                 rts
  102.  
  103.  
  104. |***************************************************************************
  105. |                             GLOBAL TEXT SECTION                             *
  106. |***************************************************************************
  107.  
  108. |***************************************************************************
  109. |
  110. |  nkc_init: initialize NKCC
  111. |
  112. |***************************************************************************
  113.  
  114. _nkc_init:
  115. |------------- fetch addresses of TOS' key scan code translation tables
  116.  
  117.                 moveql    #-1,d0                | the function is also used to
  118.                 movel    d0,sp@-             | change the addresses| values
  119.                 movel    d0,sp@-             | of -1 as new addresses tell
  120.                 movel    d0,sp@-             | XBIOS not to change them
  121.                 movew    #0x10,sp@-            | Keytbl
  122.                 trap     #14                 | XBIOS
  123.                 lea        sp@(0xe),sp         | clean stack
  124.  
  125.                 movel    d0,a0                | ^key table structure
  126.                 movel    a0@+,pkey_unshift    | get ^unshifted table
  127.                 movel    a0@+,pkey_shift     | get ^shifted table
  128.                 movel    a0@,pkey_caps        | get ^CapsLock table
  129.  
  130. exit1:            movew    #VERSION,d0         | load version #
  131.                 rts                            | bye
  132.  
  133. |***************************************************************************
  134. |
  135. |  nkc_tconv: TOS key code converter
  136. |
  137. |***************************************************************************
  138.  
  139. _nkc_tos2n:
  140.                 movel    sp@(4), d0            | Parameter über Stack!
  141.  
  142. |------------- separate TOS key code
  143.  
  144.                 movel    d0,d1                | TOS key code
  145.                 swap     d1                    | .W = scan code and flags
  146.                 movew    d1,d2                | copy
  147.                 movew    #0xff,d3            | and-mask
  148.                 andw     d3,d0                | .B = ASCII code
  149.                 andw     d3,d1                | .B = scan code
  150.                 beq        tos306                | scancode=zero (key code created
  151.                                             |    by ASCII input of TOS 3.06)? ->
  152.                 andw     #0x1f00,d2            | .W = key flags (in high byte)
  153.  
  154. |------------- decide which translation table to use
  155.  
  156.                 movew    d2,d3                | key flags
  157.                 andw     #NKFf_SHIFT,d3        | isolate bits for shift keys
  158.                 beqs     ktab11                | shift key pressed? no->
  159.  
  160.                 movel    pkey_shift,a0        | yes: use shift table
  161.                 bras     ktab13                | ->
  162.  
  163. ktab11:         btst     #NKFb_CAPS,d2        | CapsLock?
  164.                 beqs     ktab12                | no->
  165.  
  166.                 movel    pkey_caps,a0        | yes: use CapsLock table
  167.                 bras     ktab13                | ->
  168.  
  169. ktab12:         movel    pkey_unshift,a0     | use unshifted table
  170.  
  171. |------------- check if scan code is out of range
  172. |
  173. | Illegal scancodes can be used to produce 'macro key codes'. Their format is:
  174. |
  175. | - the scancode must be 0x84 or larger (should be 0xff to work properly with old
  176. |    versions of Mag!x)
  177. | - the ASCII code must be in the range 0x20...0xff (values below are set to 0x20
  178. |    by NKCC)
  179. | - Alternate and Control are not used for the normalized key code. However,
  180. |    if at least one of them is non-zero, then the numeric keypad flag will be
  181. |    set in the resulting key code.
  182. |
  183.  
  184. ktab13:            cmpb     #0x84,d1            | illegal scan code?
  185.                 bcss     ktab14                | no ->
  186.  
  187.                 movew    d2,d1                | flags
  188. |                andw     #NKFf_ALT|NKFf_CTRL,d1    | Alternate or Control?
  189.                 andw     #0xc00,d1            | Alternate or Control?
  190.                 beqs     special             | no ->
  191.  
  192.                 orw        #NKFf_NUM,d0        | yes: set numeric keypad flag
  193. |                and        #NKFf_CAPS|NKFf_SHIFT,d2    | mask off both flags
  194.                 andw     #0x1300,d2            | mask off both flags
  195.  
  196. special:        orw        d2,d0                | combine with ASCII code
  197. |                orw        #NKFf_FUNC|NKFf_RESVD,d0    | set function and resvd
  198.                 orw        #0x1300,d0            | set function and resvd
  199.                 cmpb     #0x20,d0            | ASCII code in range?
  200.                 bcc        exit2                | yes ->
  201.  
  202.                 moveb    #0x20,d0            | no: use minimum
  203.                 bra        exit2                | ->
  204.  
  205. |------------- check if Alternate + number: they have simulated scan codes
  206.  
  207. ktab14:         cmpb     #0x78,d1            | scan code of Alt + number?
  208.                 bcss     scan1                | no->
  209.  
  210.                 subb     #0x76,d1            | yes: calculate REAL scan code
  211.                 moveb    a0@(d1:w),d0        | fetch ASCII code
  212.                 orw        #NKFf_ALT,d2        | set Alternate flag
  213.                 bra        cat_codes            | -> add flag byte and exit
  214.  
  215. |------------- check if exception scan code from cursor keypad
  216.  
  217. scan1:            lea        xscantab,a1         | ^exception scan code table
  218.  
  219. search_scan:    movew    a1@+,d3             | NKC and scan code
  220.                 bmis     tabend                | <0? end of table reached ->
  221.  
  222.                 cmpb     d1,d3                | scan code found?
  223.                 bnes     search_scan         | no: continue search ->
  224.  
  225.                 lsrw     #8,d3                | .B = NKC
  226.                 moveql    #0,d0                | mark: key code found
  227.                 bras     scan2                | ->
  228.  
  229. tabend:         moveql    #0,d3                | no NKC found yet
  230.  
  231. |------------- check if rubbish ASCII code and erase it, if so
  232.  
  233. scan2:            moveb    a0@(d1:w),d4        | ASCII code from translation table
  234.                 cmpb     #32,d0                | ASCII returned by TOS < 32?
  235.                 bccs     scan3                | no -> can't be rubbish
  236.  
  237.                 cmpb     d4,d0                | yes: compare with table entry
  238.                 beqs     scan3                | equal: that's ok ->
  239.  
  240.                 moveql    #0,d0                | not equal: rubbish! clear it
  241.  
  242. |------------- check if ASCII code could only be produced via Alternate key
  243. |                combination
  244.  
  245. scan3:            tstb     d0                    | ASCII code valid?
  246.                 beqs     scan4                | no ->
  247.  
  248.                 cmpb     d4,d0                | compare with table entry
  249.                 beqs     scan4                | equal: normal key ->
  250.  
  251. |                and        #!NKFf_ALT,d2        | no: clear Alternate flag
  252.                 andw     #0xF7FF,d2            | no: clear Alternate flag
  253.  
  254. |------------- check if ASCII code found yet, and set it, if not
  255.  
  256. scan4:            tstb     d0                    | found?
  257.                 bnes     scan5                | yes ->
  258.  
  259.                 moveb    d3,d0                | no: use code from exception table
  260.                 bnes     scan5                | now valid? yes ->
  261.  
  262.                 moveb    d4,d0                | no: use code from transl. table
  263.  
  264. |------------- check special case: delete key
  265.  
  266. scan5:            cmpb     #127,d0             | ASCII code of Delete?
  267.                 bnes     scan6                | no ->
  268.  
  269.                 moveb    #NK_DEL,d0            | yes: set according NKC
  270.  
  271. |------------- check if key is on numeric keypad (via scan code)
  272.  
  273. scan6:            cmpb     #0x4a,d1            | numeric pad scan code range?
  274.                 beqs     numeric             | yes ->
  275.  
  276.                 cmpb     #0x4e,d1
  277.                 beqs     numeric             | yes ->
  278.  
  279.                 cmpb     #0x63,d1
  280.                 bcss     scan7                | no ->
  281.  
  282.                 cmpb     #0x72,d1
  283.                 bhis     scan7                | no ->
  284.  
  285. numeric:        orw        #NKFf_NUM,d2        | yes: set numeric bit
  286.  
  287. |------------- check if "function key" and set bit accordingly
  288.  
  289. scan7:            cmpb     #32,d0                | ASCII code less than 32?
  290.                 bccs     scan8                | no ->
  291.  
  292.                 orw        #NKFf_FUNC,d2        | yes: set function bit
  293.  
  294. |------------- check special case: Return or Enter key
  295.  
  296.                 cmpb     #13,d0                | Return or Enter key?
  297.                 bnes     scan8                | no ->
  298.  
  299.                 btst     #NKFb_NUM,d2        | yes: from the numeric pad?
  300.                 beqs     scan8                | no -> it's Return, keep code
  301.  
  302.                 moveql    #NK_ENTER,d0        | yes: it's Enter| new code
  303.  
  304. |------------- check if function key (F1-F10) via scan code
  305.  
  306. scan8:            cmpb     #0x54,d1            | shift + function key?
  307.                 bcss     scan9                | no ->
  308.  
  309.                 cmpb     #0x5d,d1
  310.                 bhis     scan9                | no ->
  311.  
  312.                 subb     #0x54-0x3b,d1        | yes: scan code for unshifted key
  313.                 movew    d2,d3                | shift flags
  314.                 andw     #NKFf_SHIFT,d3        | any shift key flag set?
  315.                 bnes     scan9                | yes ->
  316.                 orw        #NKFf_SHIFT,d2        | no: set both flags
  317.  
  318. scan9:            cmpb     #0x3b,d1            | (unshifted) function key?
  319.                 bcss     cat_codes            | no ->
  320.  
  321.                 cmpb     #0x44,d1
  322.                 bhis     cat_codes            | no ->
  323.  
  324.                 moveb    d1,d0                | yes: calc NKC
  325.                 subb     #0x2b,d0
  326.  
  327. |------------- final flag handling| mix key code (low byte) and flag byte
  328.  
  329. cat_codes:        movel    pkey_shift,a0        | ^shifted table
  330.                 moveb    a0@(d1:w),d3            | get shifted ASCII code
  331.                 orw        d2,d0                | mix flags with key code
  332.                 bmis     scan10                | result is "function key"? ->
  333.  
  334.                 andw     #NKFf_CTRL+NKFf_ALT,d2    | Control or Alternate pressed?
  335.                 bnes     scan11                | yes ->
  336.  
  337. scan10:         movel    pkey_unshift,a0     | ^unshifted table
  338.                 cmpb     a0@(d1:w),d3        | shifted ASCII = unshifted ASCII?
  339.                 beqs     scan12                | yes ->
  340.  
  341.                 bras     exit2                | no ->
  342.  
  343. scan11:         orw        #NKFf_FUNC,d0        | Alt/Ctrl + char: set function bit
  344.                 movel    pkey_caps,a0        | ^CapsLock table
  345.                 cmpb     a0@(d1:w),d3        | shifted ASCII = CapsLocked ASCII?
  346.                 bnes     exit2                | no ->
  347.  
  348.                 moveb    d3,d0                | yes: use shifted ASCII code
  349.  
  350. scan12:         orw        #NKFf_RESVD,d0        | yes: nkc_cmp() has to check
  351.  
  352. |------------- restore registers and exit
  353.  
  354. exit2:            tstw     d0                    | set CCR
  355.                 rts                            | bye
  356.  
  357. |------------- special handling for key codes created by TOS' 3.06 ASCII input
  358.  
  359. tos306:         andw     #NKFf_CAPS,d2        | isolate CapsLock flag
  360.                 orw        d2,d0                | merge with ASCII code
  361.                 rts                            | bye
  362.  
  363.  
  364. |***************************************************************************
  365. |
  366. |  nkc_n2tos: convert normalized key codes back to TOS format
  367. |
  368. |***************************************************************************
  369.  
  370. _nkc_n2tos:     
  371.                 movel    sp@(4),d0            | Parameter über Stack!
  372.  
  373.                 movew    d0,d1                | normalized key code
  374. |                and        #NKFf_FUNC|NKFf_ALT|NKFf_CTRL,d1| isolate flags
  375.                 andw     #0x8c00,d1            | isolate flags
  376.                 cmpw     #NKFf_FUNC,d1        | only function flag set?
  377.                 bnes     ktab20                | no ->
  378.  
  379.                 cmpb     #0x20,d0            | ASCII code >= 0x20?
  380.                 bcss     ktab20                | no ->
  381.  
  382. |------------- macro key
  383.  
  384.                 movew    d0,d1                | keep normalized key code
  385. |                andl     #NKFf_CAPS|NKFf_SHIFT,d0    | isolate usable flags
  386.                 andl     #0x1300,d0            | mask off both flags
  387.                 btst     #NKFb_NUM,d1        | numeric keypad flag set?
  388.                 beqs     mackey                | no ->
  389.  
  390. |                or        #NKFf_ALT|NKFf_CTRL,d0    | yes: set Alternate + Control
  391.                 orw        #0xc00,d1            | yes: set Alternate + Control?
  392.  
  393. mackey:         orb        #0xff,d0            | scan code always 0xff
  394.                 swap     d0                    | flags and scan code in upper word
  395.                 moveb    d1,d0                | ASCII code
  396.                 bra        exit3                | ->
  397.  
  398. |------------- select system key table to use
  399.  
  400. ktab20:         movew    d0,d1                | normalized key code
  401.                 andw     #NKFf_SHIFT,d1        | isolate bits for shift keys
  402.                 beqs     ktab21                | shift key pressed? no->
  403.  
  404.                 lea        n_to_scan_s,a1        | ^default translation table
  405.                 movel    pkey_shift,a0        | yes: use shift table
  406.                 bras     ktab23                | ->
  407.  
  408. ktab21:         lea        n_to_scan_u,a1        | ^unshifted translation table
  409.                 btst     #NKFb_CAPS,d0        | CapsLock?
  410.                 beqs     ktab22                | no->
  411.  
  412.                 movel    pkey_caps,a0        | yes: use CapsLock table
  413.                 bras     ktab23                | ->
  414.  
  415. ktab22:         movel    pkey_unshift,a0     | use unshifted table
  416.  
  417. |------------- handling for ASCII codes >= 32
  418.  
  419. ktab23:         cmpb     #32,d0                | ASCII code < 32?
  420.                 bcss     lowascii            | yes ->
  421.  
  422.                 bsr        nk_findscan         | find scan code
  423.                 bnes     found2                | found ->
  424.  
  425.                 btst     #NKFb_FUNC,d0        | function flag set?
  426.                 beqs     notfound            | no ->
  427.  
  428.                 movel    a0,d1                | save a0
  429.                 lea        tolower,a0            | ^upper->lower case table
  430.                 moveql    #0,d2                | clear for word operation
  431.                 moveb    d0,d2                | ASCII code
  432.                 moveb    a0@(d2:w),d0        | get lowercased ASCII code
  433.                 movel    d1,a0                | restore a0
  434.                 bsr        nk_findscan         | try to find scan code again
  435.                 bnes     found2                | found ->
  436.  
  437. |------------- unknown source: treat key code as it was entered using the
  438. |                TOS 3.06 direct ASCII input
  439.  
  440. notfound:        moveql    #0,d1                | not found: clear for word op.
  441.                 moveb    d0,d1                | unchanged ASCII code
  442.                 andw     #0x1f00,d0            | keep shift flags only
  443.                 swap     d0                    | -> high word (scan code = 0)
  444.                 movew    d1,d0                | low word: ASCII code
  445.                 bra        exit3                | ->
  446.  
  447. |------------- handling for ASCII codes < 32
  448.  
  449. lowascii:        btst     #NKFb_FUNC,d0        | function key?
  450.                 bnes     func                | yes ->
  451.  
  452.                 andw     #0x10ff,d0            | clear all flags except CapsLock
  453.                 bras     notfound            | ->
  454.  
  455. func:            moveql    #0,d1                | clear for word operation
  456.                 moveb    d0,d1                | ASCII code (0...0x1f)
  457.                 movew    d1,d2                | copy
  458.                 moveb    a1@(d1:w),d1        | get scan code
  459.                 bnes     getascii            | valid? ->
  460.  
  461.                 moveq    #0,d0                | invalid key code!! return 0
  462.                 bra        exit3                | ->
  463.  
  464. getascii:        lea        n_to_scan_u,a1        | ^unshifted translation table
  465.                 moveb    a1@(d2:w),d2        | get scan code from unshifted tab.
  466.                 moveb    a0@(d2:w),d0        | get ASCII from system's table
  467.  
  468. | register contents:
  469. |
  470. | d0.b            ASCII code
  471. | d1.b            scan code
  472. | d0.hb         NKCC flags
  473. |
  474.  
  475. found2:         movew    d0,d2                | flags and ASCII code
  476.                 andw     #0x1f00,d0            | isolate shift flags
  477.                 moveb    d1,d0                | merge with scan code
  478.                 swap     d0                    | -> high byte
  479.                 clrw     d0                    | erase low word
  480.                 moveb    d2,d0                | restore ASCII code
  481.  
  482. |------------- handling for Control key flag
  483.  
  484.                 btst     #NKFb_CTRL,d2        | control key flag set?
  485.                 beqs     alternate            | no ->
  486.  
  487.                 cmpb     #0x4b,d1            | scan code = "cursor left"?
  488.                 bnes     scanchk2            | no ->
  489.  
  490.                 addl     #0x280000,d0        | change scan code to 0x73
  491.                 clrb     d0                    | erase ASCII code
  492.                 bras     exit3                | ->
  493.  
  494. scanchk2:         cmpb     #0x4d,d1            | scan code = "cursor right"?
  495.                 bnes     scanchk3            | no ->
  496.  
  497.                 addl     #0x270000,d0        | change scan code to 0x74
  498.                 clrb     d0                    | erase ASCII code
  499.                 bras     exit3                | ->
  500.  
  501. scanchk3:         cmpb     #0x47,d1            | scan code = "ClrHome"?
  502.                 bnes     ascchk                | no ->
  503.  
  504.                 addl     #0x300000,d0        | change scan code to 0x77
  505. | keep ASCII code in this case! What a mess...
  506.                 bras     exit3                | ->
  507.  
  508. ascchk:         lea        asc_trans,a0        | ^ASCII translation table
  509.  
  510. ascloop:        movew    a0@+,d1             | get next entry
  511.                 beqs     noctrlasc            | end of table ->
  512.  
  513.                 cmpb     d0,d1                | ASCII code found?
  514.                 bnes     ascloop             | no -> continue search
  515.  
  516.                 lsrw     #8,d1                | yes: get translated code
  517.                 moveb    d1,d0                | use it
  518.                 bras     exit3                | ->
  519.  
  520. noctrlasc:        andb     #0x1f,d0            | mask off upper 3 bits
  521.                 bras     exit3                | ->
  522.  
  523. |------------- handling for Alternate key flag
  524.  
  525. alternate:        btst     #NKFb_ALT,d2        | alternate key flag set?
  526.                 beqs     exit3                | no ->
  527.  
  528.                 cmpb     #2,d1                | top row on main keyboard?
  529.                 bcss     alphachk            | no ->
  530.  
  531.                 cmpb     #0xd,d1
  532.                 bhis     alphachk            | no ->
  533.  
  534.                 addl     #0x760000,d0        | yes: change scan code
  535.                 clrb     d0                    | and erase ASCII code
  536.                 bras     exit3                | ->
  537.  
  538. alphachk:        cmpb     #65,d0                | alpha-characters?
  539.                 bcss     exit3                | no ->
  540.  
  541.                 cmpb     #122,d0
  542.                 bhis     exit3                | no ->
  543.  
  544.                 cmpb     #90,d0
  545.                 blss     ascii0                | yes ->
  546.  
  547.                 cmpb     #97,d0
  548.                 bcss     exit3                | no ->
  549.  
  550. ascii0:         clrb     d0                    | alpha-character: clear ASCII code
  551.  
  552. exit3:            tstw     d0                    | set CCR
  553.                 rts                            | bye
  554.  
  555.  
  556. |***************************************************************************
  557. |
  558. |  nkc_toupper: convert character to upper case
  559. |
  560. |***************************************************************************
  561.  
  562. _nkc_toupper:    movel    sp@(4),d1            | Parameter über Stack!
  563.                 lea        toupper,a0            | ^upper case translation table
  564.                  andw    #0xff,d1            | high byte = 0 for word operation
  565.                 moveb    a0@(d1:l),d0        | convert
  566.                 rts                            | bye
  567.  
  568. |***************************************************************************
  569. |
  570. |  nkc_tolower: convert character to lower case
  571. |
  572. |***************************************************************************
  573.  
  574. _nkc_tolower:    movel    sp@(4),d1            | Parameter über Stack!
  575.                 lea        tolower,a0            | ^lower case translation table
  576.                 andw     #0xff,d1            | high byte = 0 for word operation
  577.                 moveb    a0@(d1:l),d0        | convert
  578.                 rts                            | bye
  579.  
  580. |***************************************************************************
  581. |                             LOCAL DATA SECTION                              *
  582. |***************************************************************************
  583.  
  584.                 .data
  585.  
  586. |  exception scan code table for cursor block keys
  587. |
  588. |  first entry.B:  NKCC key code
  589. |  second entry.B: scan code returned by TOS
  590. |
  591. |  the table is terminated with both entries -1
  592.  
  593. xscantab:        .byte    NK_UP        ,  0x48 | cursor up
  594.                 .byte    NK_DOWN     ,    0x50 | cursor down
  595.                 .byte    NK_LEFT     ,    0x4b | cursor left
  596.                 .byte    NK_LEFT     ,    0x73 | Control cursor left
  597.                 .byte    NK_RIGHT    ,    0x4d | cursor right
  598.                 .byte    NK_RIGHT    ,    0x74 | Control cursor right
  599.                 .byte    NK_M_PGUP    ,  0x49 | Mac: page up
  600.                 .byte    NK_M_PGDOWN ,  0x51 | Mac: page down
  601.                 .byte    NK_M_END    ,    0x4f | Mac: end
  602.                 .byte    NK_INS        ,  0x52 | Insert
  603.                 .byte    NK_CLRHOME    ,  0x47    | ClrHome
  604.                 .byte    NK_CLRHOME    ,  0x77    | Control ClrHome
  605.                 .byte    NK_HELP     ,    0x62 | Help
  606.                 .byte    NK_UNDO     ,    0x61 | Undo
  607.                 .byte    NK_M_F11    ,    0x45 | Mac: F11
  608.                 .byte    NK_M_F12    ,    0x46 | Mac: F12
  609.                 .byte    NK_M_F14    ,    0x37 | Mac: F14
  610.                 .word    -1
  611.  
  612. |  lower case to upper case conversion table
  613. |  (array of 256 unsigned bytes)
  614. toupper:
  615.             .byte 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  616.             .byte 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  617.             .byte 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17
  618.             .byte 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
  619.             .byte 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27
  620.             .byte 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F
  621.             .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37
  622.             .byte 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F
  623.             .byte 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47
  624.             .byte 0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F
  625.             .byte 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57
  626.             .byte 0x58,0x59,0x5A,0x5B,0x5c,0x5D,0x5E,0x5F
  627.             .byte 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47
  628.             .byte 0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F
  629.             .byte 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57
  630.             .byte 0x58,0x59,0x5A,0x7B,0x7C,0x7D,0x7E,0x7F
  631.             .byte 0x80,0x9A,0x90,0x83,0x8E,0xB6,0x8F,0x80
  632.             .byte 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F
  633.             .byte 0x90,0x92,0x92,0x93,0x99,0x95,0x96,0x97
  634.             .byte 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F
  635.             .byte 0xA0,0xA1,0xA2,0xA3,0xA5,0xA5,0xA6,0xA7
  636.             .byte 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF
  637.             .byte 0xB7,0xB8,0xB2,0xB2,0xB5,0xB5,0xB6,0xB7
  638.             .byte 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF
  639.             .byte 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7
  640.             .byte 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF
  641.             .byte 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7
  642.             .byte 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF
  643.             .byte 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7
  644.             .byte 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF
  645.             .byte 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7
  646.             .byte 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF
  647.  
  648.  
  649. |  upper case to lower case conversion table
  650. |  (array of 256 unsigned bytes)
  651. tolower:
  652.             .byte 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  653.             .byte 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  654.             .byte 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17
  655.             .byte 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f
  656.             .byte 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27
  657.             .byte 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F
  658.             .byte 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37
  659.             .byte 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F
  660.             .byte 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67
  661.             .byte 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F
  662.             .byte 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77
  663.             .byte 0x78,0x79,0x7A,0x5B,0x5C,0x5D,0x5E,0x5F
  664.             .byte 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67
  665.             .byte 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F
  666.             .byte 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77
  667.             .byte 0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F
  668.             .byte 0x87,0x81,0x82,0x83,0x84,0x85,0x86,0x87
  669.             .byte 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x84,0x86
  670.             .byte 0x82,0x91,0x91,0x93,0x94,0x95,0x96,0x97
  671.             .byte 0x98,0x94,0x81,0x9B,0x9C,0x9D,0x9E,0x9F
  672.             .byte 0xA0,0xA1,0xA2,0xA3,0xA4,0xA4,0xA6,0xA7
  673.             .byte 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF
  674.             .byte 0xB0,0xB1,0xB3,0xB3,0xB4,0xB4,0x85,0xB0
  675.             .byte 0xB1,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF
  676.             .byte 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7
  677.             .byte 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF
  678.             .byte 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7
  679.             .byte 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF
  680.             .byte 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7
  681.             .byte 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF
  682.             .byte 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7
  683.             .byte 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF
  684.  
  685.  
  686. |  ASCII code translation table for Control key
  687. |
  688. |  first entry.B:  modified ASCII code returned by TOS
  689. |  second entry.B: original ASCII code as stored in key table
  690. |
  691. |  The table is terminated with both entries 0
  692.  
  693. asc_trans:        .byte    0,0x32                | Control '2' becomes ASCII 0
  694.                 .byte    0x1e,0x36            | Control '6' becomes ASCII 0x1e
  695.                 .byte    0x1f,0x2d            | Control '-' becomes ASCII 0x1f
  696.                 .byte    0xa,0xd             | Control Return/Enter: 0xd -> 0xa
  697.                 .word    0                    | terminator
  698.  
  699.  
  700. |  normalized key code -> scan code translation table
  701. |  for unshifted key codes
  702. |  indexed by function code (NK_...)
  703.  
  704. n_to_scan_u:    .byte    0x00                | invalid key code
  705.                 .byte    0x48                | cursor up
  706.                 .byte    0x50                | cursor down
  707.                 .byte    0x4d                | cursor right
  708.                 .byte    0x4b                | cursor left
  709.                 .byte    0x49                | Mac: page up
  710.                 .byte    0x51                | Mac: page down
  711.                 .byte    0x4f                | Mac: end
  712.                 .byte    0x0e                | Backspace
  713.                 .byte    0x0f                | Tab
  714.                 .byte    0x72                | Enter
  715.                 .byte    0x52                | Insert
  716.                 .byte    0x47                | ClrHome
  717.                 .byte    0x1c                | Return
  718.                 .byte    0x62                | Help
  719.                 .byte    0x61                | Undo
  720.                 .byte    0x3b                | function key #1
  721.                 .byte    0x3c                | function key #2
  722.                 .byte    0x3d                | function key #3
  723.                 .byte    0x3e                | function key #4
  724.                 .byte    0x3f                | function key #5
  725.                 .byte    0x40                | function key #6
  726.                 .byte    0x41                | function key #7
  727.                 .byte    0x42                | function key #8
  728.                 .byte    0x43                | function key #9
  729.                 .byte    0x44                | function key #10
  730.                 .byte    0x45                | Mac: F11
  731.                 .byte    0x01                | Esc
  732.                 .byte    0x46                | Mac: F12
  733.                 .byte    0x37                | Mac: F14
  734.                 .byte    0x00                | reserved!
  735.                 .byte    0x53                | Delete
  736.  
  737. |  normalized key code -> scan code translation table
  738. |  for shifted key codes
  739. |  indexed by function code (NK_...)
  740.  
  741. n_to_scan_s:    .byte    0x00                | invalid key code
  742.                 .byte    0x48                | cursor up
  743.                 .byte    0x50                | cursor down
  744.                 .byte    0x4d                | cursor right
  745.                 .byte    0x4b                | cursor left
  746.                 .byte    0x49                | Mac: page up
  747.                 .byte    0x51                | Mac: page down
  748.                 .byte    0x4f                | Mac: end
  749.                 .byte    0x0e                | Backspace
  750.                 .byte    0x0f                | Tab
  751.                 .byte    0x72                | Enter
  752.                 .byte    0x52                | Insert
  753.                 .byte    0x47                | ClrHome
  754.                 .byte    0x1c                | Return
  755.                 .byte    0x62                | Help
  756.                 .byte    0x61                | Undo
  757.                 .byte    0x54                | function key #1
  758.                 .byte    0x55                | function key #2
  759.                 .byte    0x56                | function key #3
  760.                 .byte    0x57                | function key #4
  761.                 .byte    0x58                | function key #5
  762.                 .byte    0x59                | function key #6
  763.                 .byte    0x5a                | function key #7
  764.                 .byte    0x5b                | function key #8
  765.                 .byte    0x5c                | function key #9
  766.                 .byte    0x5d                | function key #10
  767.                 .byte    0x45                | Mac: F11
  768.                 .byte    0x01                | Esc
  769.                 .byte    0x46                | Mac: F12
  770.                 .byte    0x37                | Mac: F14
  771.                 .byte    0x00                | reserved!
  772.                 .byte    0x53                | Delete
  773.  
  774. |***************************************************************************
  775. |                              LOCAL BSS SECTION                              *
  776. |***************************************************************************
  777.  
  778. |                .bss
  779.  
  780. pkey_unshift:    .long    1                    | ^unshifted key table
  781. pkey_shift:        .long    1                    | ^shifted key table
  782. pkey_caps:        .long    1                    | ^CapsLock table
  783.  
  784. | End Of File
  785.